# -*- encoding: utf-8 -*-
'''
@File    :   mojofm.py
@Time    :   2021/12/26 01:51:55
@Author  :   January.Plus 
@Wechat  :   cjy4959
'''
# here put the import lib

import subprocess
import os
        
def mojofm(arc_file_1:str,arc_file_2:str):
    # print(os.path.dirname(os.path.abspath(__file__)))
    mojo_2_0_path:str=None
    for dirpath, dirnames, _ in os.walk(os.path.dirname(os.path.abspath(__file__))):
        for dir in dirnames:
            if dir == 'mojo_2.0':
                # print(os.path.join(dirpath,dir))
                mojo_2_0_path = os.path.join(dirpath,dir)
                break 
    if not os.path.isdir(mojo_2_0_path):
        print("mojo path is invalid.")
        exit(1)
    cmd = ["java","mojo.MoJo",arc_file_1,arc_file_2,"-fm"]
    p = subprocess.Popen(cmd
                         ,cwd=mojo_2_0_path
                         ,stdout=subprocess.PIPE
                         )
    ret = p.stdout.readline()
    return float(ret.strip())
    
if __name__ == '__main__':
    ret = mojofm(
        "/Users/plus/Desktop/module-reverse-by-gnn/GraphEmbedding/data/bash/symbol/tuning/tmp/2283763.rsf"
        ,"/Users/plus/Desktop/module-reverse-by-gnn/GraphEmbedding/data/bash/bash_gt.rsf"
    )

    print(ret)